/*
 * Copyright 2013 Glassy Cinema.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hu.glassy.core.model;

import hu.glassy.model.common.AbstractEntity;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Represents the user account
 *
 * @author Alexander Molnár <molnar.alexander@sonrisa.hu>
 */
@Entity
@Table(name = "account")
public class Account extends AbstractEntity
{

  private static final long serialVersionUID = -3152051723166159564L;

  public static final int NAME_LENGTH = 128;
  public static final int EMAIL_LENGTH = 256;
  public static final int PASSWORD_LENGTH = 32;

  /**
   * Jelzi, hogy egy újonnan létrehozott felhasználó account-ja aktív legyen-e
   */
  public static final Boolean DEFAULT_ACTIVE = Boolean.FALSE;

  /**
   * Az újonnan létrehozott felhasználó nem admin
   */
  private static final Boolean DEFAULT_ADMIN = Boolean.FALSE;

  @Column(name = "active", nullable = false, unique = false)
  private Boolean active = DEFAULT_ACTIVE;

  @Column(name = "name", length = NAME_LENGTH, nullable = false, unique = true)
  private String name;

  @Column(name = "email", length = EMAIL_LENGTH, nullable = false)
  private String email;

  @Column(name = "password", length = PASSWORD_LENGTH, nullable = false, unique = false)
  private String password;

  @Column(name = "isadmin", nullable = false, unique = false)
  private Boolean isAdmin = DEFAULT_ADMIN;

  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "registrationdate", nullable = false, unique = false)
  private Date registrationDate = new Date();

  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "lastlogin", nullable = true, unique = false)
  private Date lastLogin;

  public Boolean isActive()
  {
    return active;
  }

  public void setActive(final Boolean active)
  {
    this.active = active;
  }

  public String getName()
  {
    return name;
  }

  public void setName(final String name)
  {
    this.name = name;
  }

  public String getEmail()
  {
    return email;
  }

  public void setEmail(final String email)
  {
    this.email = email;
  }

  public String getPassword()
  {
    return password;
  }

  public void setPassword(final String password)
  {
    this.password = password;
  }

  public Boolean isAdmin()
  {
    return isAdmin;
  }

  public void setAdmin(final Boolean isAdmin)
  {
    this.isAdmin = isAdmin;
  }

  public Date getLastLogin()
  {
    return lastLogin;
  }

  public void setLastLogin(final Date lastLogin)
  {
    this.lastLogin = lastLogin;
  }

  public Date getRegistrationDate()
  {
    return registrationDate;
  }

  public void setRegistrationDate(final Date registrationDate)
  {
    this.registrationDate = registrationDate;
  }
}
